<template>
	<view>
		<view class="indexDatas">
			<view class="walletItem">
				<view class="walletTitle flex align-center justify-between">
					<view>余额：<text style="font-size: 32upx;color:#ff537b;font-weight: bold;">{{wallet.balance}}</text></view>
				</view>	
				<view class="dataBox">
					<input placeholder="请输入对方手机号" v-model="mobile"/>
					<!-- <text style="font-size: 40upx;" class="text-gray cuIcon-scan" @click="saoma"></text> -->
				</view>
				<text class="user" v-if="user">用户：{{user.nickname}}</text>
				<view class="dataBox">
					<input type="number" placeholder="请输转账入数量" v-model="money"/>
					<!-- <text>{{type==4?'USDT':'LCL'}}</text> -->
				</view>
				<view class="dataBox">
					<input :password="!ifshow" type="text" placeholder="支付密码" v-model="password"/>
					<text v-if="!ifshow" class="lg text-gray cuIcon-attentionforbid" style="font-size: 40upx;" @click="ifshow = !ifshow"></text>
					<text v-else class="lg text-gray cuIcon-attentionfavor" style="font-size: 40upx;" @click="ifshow = !ifshow"></text>
				</view>
				<button class="buyBtn" @click="postTransfer">确定</button>
			</view>
			<view class="tips">提示：单笔转币收取手续费{{wallet.rate}}%</view>
		</view>
	</view> 
</template>

<script>
	import {
		post,
		get,
		abortPost
	} from "@/utils/post.js";
	export default {
		data() {
			return { 
				ifshow:false,
				money:'',
				password:'',
				wallet:'',
				mobile:'',
				type:'',
				walletName:'',
				user:''
			}
		}, 
		onLoad(op){
			this.type = op.type
			this.init()
		},
		watch:{
			mobile(){
				if(this.mobile){
					abortPost()
					this.getUser()
				}
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url:'/pages/WB/details?type='+this.type
			})
		},
		methods: {
			getUser(){
				post(this.$api.wallet.getuser,{mobile:this.mobile},false,res=>{
					this.user = res.data
				})
			},
			init() {
				this.$sloading()
				this.$request({
					url: this.$api.wallet.transfer_conf,
					method:'post',
					data: {	
						b_type: this.type
					}
				}).then(info => {
					this.$hloading()
					if (info.code == 0) {
						this.wallet = info.data
					}
				}).catch(info => {
					this.$hloading()
				})
			},
			saoma(){
				var that = this
				uni.scanCode({
				    scanType: 'qrCode',
				    success: function (res) {
						console.log(res.result)
						that.mobile = res.result
				    }
				});
			},
			postTransfer(){
				if(!this.user){
					this.$showM('请输入正确的手机号',false)
					return
				}
				if(!this.money){
					this.$showM('请输入转账数量',false)
					return
				}
				if(!this.password){
					this.$showM('请输入支付密码',false)
					return
				}
				var data = {
					b_type:this.type,
					user_id:this.user.id,
					password:this.password,
					money:this.money
				}
				this.$sloading()
				this.$request({
					url: this.$api.wallet.transfer,
					method:'post',
					data:data
				}).then(info => {
					this.$hloading()
					if (info.code == 0) {
						this.$showM('转账成功',false)
						this.password = ''
						this.money = ''
						this.init()
					}else{
						this.$showM(info.msg,false)
					}
				}).catch(info => {
					this.$hloading()
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.user{
		font-size: 26upx;
		color: red;
	}
	.tips{
		color: red;
		margin-top: 20upx;
		font-size: 26upx;
	}
	.buyBtn{
		height: 70upx;
		line-height: 70upx;
		font-size: 30upx;
		margin-top: 30upx;
		background-image: linear-gradient(to right,#ffd171,#ff8959);
		color: #fff;
	}
	input{
		font-size: 28upx;
		width: 480upx;
	}
	.dataNum{
		font-size: 34upx;
		color:#35c292;
		font-weight: bold;
	}
	.dataBox{
		height: 80upx;
		width: 100%;
		padding: 20upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border: 1px solid #666;
		border-radius: 6upx;
		margin-top: 40upx;
	}
	.walletTitle{
		font-size: 28upx;
	}
	.indexDatas image{	
		height: 210upx;
		width: 480upx;
		margin: 0 auto;
		display: block;
	}
	.walletItem{
		width: 700upx;
		padding: 20upx;
		border-radius: 10upx;
		box-shadow: 0 0 5px #93cdfe;
		background: #fff;
		margin-top: 50upx;
	}
	
	.fillBg{
		background: #35c292;
		height: 30upx;
		width: 100%;
	}
	
	.indexDatas{
		background: #fff;
		width:750upx;
		border-radius: 30upx 30upx 0 0;
		margin-top:-30upx;
		padding: 25upx;
		overflow-x: hidden;
	}
</style>
